let setCookie = (name, value) => {
  let exp = new Date();
  exp.setTime(exp.getTime() + 60 * 60 * 1000 * 12);
  document.cookie =
    name + "=" + escape(value) + ";expires=" + exp.toGMTString() + ";path=/";
};

let getCookie = name => {
  let arr;
  let reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
  if ((arr = document.cookie.match(reg))) {
    return unescape(arr[2]);
  } else {
    return null;
  }
};

let delCookie = name => {
  let exp = new Date();
  exp.setTime(exp.getTime() - 60 * 60 * 1000 * 12);
  let cval = getCookie(name);
  if (cval != null) {
    document.cookie =
      name + "=" + cval + ";expires=" + exp.toGMTString() + ";path=/";
  }
};

export default {
  setCookie(name, value) {
    setCookie.apply(this, [name, value]);
  },
  getCookie(name) {
    return getCookie.apply(this, [name]);
  },
  delCookie(name) {
    delCookie.apply(this, [name]);
  }
};
